package com.bsoft.gol.hcs.specialist.dao;

import ctd.persistence.annotation.DAOMethod;
import ctd.persistence.annotation.DAOParam;
import ctd.persistence.support.hibernate.HibernateSupportDelegateDAO;
import ctd.persistence.support.hibernate.template.AbstractHibernateStatelessResultAction;
import ctd.persistence.support.hibernate.template.HibernateSessionTemplate;
import ctd.persistence.support.hibernate.template.HibernateStatelessResultAction;
import com.bsoft.gol.hcs.enumcase.FollowTypeEnum;
import org.hibernate.Query;
import org.hibernate.StatelessSession;
import com.bsoft.gol.hcs.specialist.bean.request.QueryByDiagnosisRequest;
import com.bsoft.gol.hcs.specialist.bean.request.QueryByHappenTimeRequest;
import com.bsoft.gol.hcs.specialist.bean.request.QueryByIndexRequest;
import com.bsoft.gol.hcs.specialist.bean.request.QueryByOperativeRequest;
import com.bsoft.gol.hcs.specialist.bean.response.FactorData;
import com.bsoft.gol.hcs.specialist.entity.FollowUpPlanProduceRecord;
import com.bsoft.gol.hcs.specialist.entity.FollowUpRouteDetailFactorRelation;
import com.bsoft.gol.hcs.utils.CommonUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @author tongtp
 * @version v0.1
 * @className FollowUpPlanProduceRecordDAO
 * @description
 * @create 2020-07-30 9:22
 **/
public abstract class FollowUpPlanProduceRecordDAO extends HibernateSupportDelegateDAO<FollowUpPlanProduceRecord> {

    @DAOMethod(sql = " from FollowUpPlanProduceRecord where status = 1 ")
    public abstract List<FollowUpPlanProduceRecord> queryByUnFinished();

    /**
     * @param ids
     * @throws
     * @description: 根据id集合查询
     * @return: java.util.List<specialist.entity.FollowUpPlanProduceRecord>
     * @author: tongtp
     * @date: 2020/7/30 13:30
     */
    @DAOMethod(sql = "from FollowUpPlanProduceRecord where id in :ids ")
    public abstract List<FollowUpPlanProduceRecord> queryByIds(@DAOParam("ids") List<Long> ids);

    /**
     * @param patientIdList
     * @throws
     * @description: 根据病人id集合查询未终止的随访计划记录
     * @return: java.util.List<specialist.entity.FollowUpPlanProduceRecord>
     * @author: tongtp
     * @date: 2020/7/30 13:30
     */
    @DAOMethod(sql = "select a from FollowUpPlanProduceRecord a,FusTeamChronicGroupRecordEntity b where  a.teamChronicGroupId=b.teamChronicGroupId and  b.patientId in :patientIdList AND a.status=1 and b.chronicDiseaseId=:chronicDiseaseId")
    public abstract List<FollowUpPlanProduceRecord> queryByPatientIdList(@DAOParam("patientIdList") List<String> patientIdList,@DAOParam("chronicDiseaseId") Long chronicDiseaseId);


    /**
     * 根据子路径id和入组纪录id查询专病随访计划生产记录
     *
     * @param routeDetailId
     * @param teamChronicGroupId
     * @return specialist.entity.FollowUpPlanProduceRecord
     * @throws
     * @date 2022/6/2 16:03
     */
    @DAOMethod(sql = " from FollowUpPlanProduceRecord  where  routeDetailId =:routeDetailId and teamChronicGroupId =:teamChronicGroupId ")
    public abstract FollowUpPlanProduceRecord getByRouteDetailId(@DAOParam("routeDetailId") Long routeDetailId,
                                                                 @DAOParam("teamChronicGroupId") Long teamChronicGroupId);

    /**
     * @param request
     * @throws
     * @description: 根据手术和条件是查询
     * @return: java.util.List<java.lang.Long>
     * @author: tongtp
     * @date: 2020/7/23 20:24
     */
    public List<Long> queryByOperativeAndYes(final QueryByOperativeRequest request) {
        HibernateStatelessResultAction<List<Long>> action =
                new AbstractHibernateStatelessResultAction<List<Long>>() {
                    @Override
                    public void execute(StatelessSession ss) throws Exception {
                        StringBuilder sqlBuilder = new StringBuilder();
                        sqlBuilder.append("SELECT a.id from follow_up_plan_produce_record a INNER JOIN " +
                                "fus_team_chronic_group_record b on a.team_chronic_group_id = b" +
                                ".team_chronic_group_id" +
                                " " +
                                "INNER JOIN fus_answer_operative_info c ON (b.person_id = c.patient_id OR (b" +
                                ".card_type" +
                                " " +
                                "= c.card_type AND b.card_number = c.card_number)) AND c.disease_type_id = " +
                                ":diseaseTypeId AND c.operative_code = :operativeCode where a.status = 1" +
                                " AND a.route_detail_id = :routeDetailId and b.audit_time <= c.answer_time ");

                        Query query = ss.createSQLQuery(sqlBuilder.toString());
                        query.setParameter("diseaseTypeId", request.getDiseaseTypeId());
                        query.setParameter("operativeCode", request.getOperativeCode());
                        query.setParameter("routeDetailId", request.getRouteDetailId());

                        List list = query.list();
                        List<Long> voList;
                        if (CommonUtils.isNotEmpty(list)) {
                            voList = list;
                        } else {
                            voList = new ArrayList<>();
                        }
                        setResult(voList);
                    }
                };
        HibernateSessionTemplate.instance().execute(action);
        return action.getResult();
    }

    /**
     * @param request
     * @throws
     * @description: 根据手术和条件否查询
     * @return: java.util.List<java.lang.Long>
     * @author: tongtp
     * @date: 2020/7/23 20:24
     */
    public List<Long> queryByOperativeAndNO(final QueryByOperativeRequest request) {
        HibernateStatelessResultAction<List<Long>> action =
                new AbstractHibernateStatelessResultAction<List<Long>>() {
                    @Override
                    public void execute(StatelessSession ss) throws Exception {
                        StringBuilder sqlBuilder = new StringBuilder();
                        sqlBuilder.append("SELECT e.id from follow_up_plan_produce_record e INNER JOIN (" +
                                "select c.team_chronic_group_id from fus_team_chronic_group_record c LEFT JOIN ( " +
                                "select a.team_chronic_group_id from fus_team_chronic_group_record a INNER JOIN " +
                                "fus_answer_operative_info b on (a.person_id  = b.patient_id OR (a.card_type = b" +
                                ".card_type and a.card_number = b.card_number)) and a.chronic_disease_id = b" +
                                ".disease_type_id where a.chronic_disease_id = :diseaseTypeId AND b.operative_code =" +
                                " " +
                                ":operativeCode and a.audit_time <= b.answer_time ) AS d on c.team_chronic_group_id " +
                                "=" +
                                " d.team_chronic_group_id where c" +
                                ".chronic_disease_id = :diseaseTypeId AND d.team_chronic_group_id IS NULL" +
                                ") AS f on e.team_chronic_group_id = f.team_chronic_group_id where e.status = 1 AND " +
                                "e" +
                                ".route_detail_id = :routeDetailId");

                        Query query = ss.createSQLQuery(sqlBuilder.toString());
                        query.setParameter("diseaseTypeId", request.getDiseaseTypeId());
                        query.setParameter("operativeCode", request.getOperativeCode());
                        query.setParameter("routeDetailId", request.getRouteDetailId());

                        List list = query.list();
                        List<Long> voList;
                        if (CommonUtils.isNotEmpty(list)) {
                            voList = list;
                        } else {
                            voList = new ArrayList<>();
                        }
                        setResult(voList);
                    }
                };
        HibernateSessionTemplate.instance().execute(action);
        return action.getResult();
    }

    /**
     * @param request
     * @throws
     * @description: 根据指标查询
     * @return: java.util.List<java.lang.Long>
     * @author: tongtp
     * @date: 2020/7/23 19:49
     */
    public List<Long> queryByIndex(final QueryByIndexRequest request) {
        HibernateStatelessResultAction<List<Long>> action =
                new AbstractHibernateStatelessResultAction<List<Long>>() {
                    @Override
                    public void execute(StatelessSession ss) throws Exception {
                        //因素内容性质类型，1定量，2定性 3 文本,因素类型为关联指标必填
                        boolean qualitative = request.getFactorNatureType() == (byte) 2;
                        StringBuilder sqlBuilder = new StringBuilder();
                        sqlBuilder.append("SELECT a.id from follow_up_plan_produce_record a INNER JOIN " +
                                "fus_team_chronic_group_record b on a.team_chronic_group_id = b" +
                                ".team_chronic_group_id " +
                                "INNER JOIN fus_answer_check_report_info c ON (b.person_id = c.patient_id OR (b" +
                                ".card_type = c.card_type AND b.card_number = c.card_number)) AND c.disease_type_id " +
                                "= :diseaseTypeId AND c.item_id = :itemId");
                        //因素内容性质类型，1定量，2定性 3 文本,因素类型为关联指标必填
                        if (qualitative) {
                            sqlBuilder.append(" and c.item_content = :itemContent1 and b.audit_time <= c.answer_time" +
                                    " ");
                        } else {
                            sqlBuilder.append(" and c.item_content >=:itemContent1 and c.item_content <= " +
                                    ":itemContent2 and b.audit_time <= c.answer_time ");
                        }
                        sqlBuilder.append(" where a.status = 1 AND a.route_detail_id =:routeDetailId");
                        sqlBuilder.append(" UNION ");
                        sqlBuilder.append("SELECT a.id from follow_up_plan_produce_record a INNER JOIN " +
                                "fus_team_chronic_group_record b on a.team_chronic_group_id = b" +
                                ".team_chronic_group_id" +
                                " " +
                                "INNER JOIN fus_answer_inspection_report_info c ON (b.person_id = c.patient_id OR (b" +
                                ".card_type = c.card_type AND b.card_number = c.card_number)) AND c.disease_type_id " +
                                "=:diseaseTypeId AND c.item_id =:itemId");
                        //因素内容性质类型，1定量，2定性 3 文本,因素类型为关联指标必填
                        if (qualitative) {
                            sqlBuilder.append(" and c.result =:itemContent1 and b.audit_time <= c.answer_time ");
                        } else {
                            sqlBuilder.append(" and c.result >=:itemContent1  and c.result <=:itemContent2 and b" +
                                    ".audit_time <= c.answer_time ");
                        }
                        sqlBuilder.append(" where a.status = 1 AND a.route_detail_id =:routeDetailId");

                        //因为结果有字符串、整数、小数等多种情况，所以在下面，将结果值转成整数和小数，如果能转成功，则执行对应的比较SQL
                        //只有定量才会需要处理这种情况，定性不需要
                        Long longItemContent1 = null;
                        Long longItemContent2 = null;
                        Double doubleItemContent1 = null;
                        Double doubleItemContent2 = null;
                        if (!qualitative) {
                            try {
                                longItemContent1 = Long.valueOf(request.getFactorResultOne());
                                longItemContent2 = Long.valueOf(request.getFactorResultTwo());
                            } catch (Exception e) {
                                longItemContent1 = null;
                                longItemContent2 = null;
                            }
                            if (longItemContent1 != null && longItemContent2 != null) {
                                sqlBuilder.append(" UNION ");
                                sqlBuilder.append("SELECT a.id from follow_up_plan_produce_record a INNER JOIN " +
                                        "fus_team_chronic_group_record b on a.team_chronic_group_id = b" +
                                        ".team_chronic_group_id " +
                                        "INNER JOIN fus_answer_check_report_info c ON (b.person_id = c.patient_id OR" +
                                        " " +
                                        "(b" +
                                        ".card_type = c.card_type AND b.card_number = c.card_number)) AND c" +
                                        ".disease_type_id " +
                                        "=:diseaseTypeId AND c.item_id =:itemId");
                                sqlBuilder.append(" and c.item_content >=:longItemContent1 and c.item_content <=:longItemContent2 and b.audit_time <= c.answer_time ");
                                sqlBuilder.append(" where a.status = 1 AND a.route_detail_id =:routeDetailId");
                                sqlBuilder.append(" UNION ");
                                sqlBuilder.append("SELECT a.id from follow_up_plan_produce_record a INNER JOIN " +
                                        "fus_team_chronic_group_record b on a.team_chronic_group_id = b" +
                                        ".team_chronic_group_id" +
                                        " " +
                                        "INNER JOIN fus_answer_inspection_report_info c ON (b.person_id = c" +
                                        ".patient_id" +
                                        " OR (b" +
                                        ".card_type = c.card_type AND b.card_number = c.card_number)) AND c" +
                                        ".disease_type_id " +
                                        "=:diseaseTypeId AND c.item_id =:itemId");
                                sqlBuilder.append(" and c.result >=:longItemContent1  and c.result <=:longItemContent2 and" +
                                        " " +
                                        "b" +
                                        ".audit_time <= c.answer_time ");
                                sqlBuilder.append(" where a.status = 1 AND a.route_detail_id =:routeDetailId");
                            }
                            try {
                                doubleItemContent1 = Double.valueOf(request.getFactorResultOne());
                                doubleItemContent2 = Double.valueOf(request.getFactorResultTwo());
                            } catch (Exception e) {
                                doubleItemContent1 = null;
                                doubleItemContent2 = null;
                            }
                            if (doubleItemContent1 != null && doubleItemContent2 != null) {
                                sqlBuilder.append(" UNION ");
                                sqlBuilder.append("SELECT a.id from follow_up_plan_produce_record a INNER JOIN " +
                                        "fus_team_chronic_group_record b on a.team_chronic_group_id = b" +
                                        ".team_chronic_group_id " +
                                        "INNER JOIN fus_answer_check_report_info c ON (b.person_id = c.patient_id OR" +
                                        " " +
                                        "(b" +
                                        ".card_type = c.card_type AND b.card_number = c.card_number)) AND c" +
                                        ".disease_type_id " +
                                        "=:diseaseTypeId AND c.item_id =:itemId");
                                sqlBuilder.append(" and c.item_content >=:bigDecimalItemContent1 and c.item_content " +
                                        "<=:bigDecimalItemContent2 and b.audit_time <= c.answer_time ");
                                sqlBuilder.append(" where a.status = 1 AND a.route_detail_id =:routeDetailId");
                                sqlBuilder.append(" UNION ");
                                sqlBuilder.append("SELECT a.id from follow_up_plan_produce_record a INNER JOIN " +
                                        "fus_team_chronic_group_record b on a.team_chronic_group_id = b" +
                                        ".team_chronic_group_id" +
                                        " " +
                                        "INNER JOIN fus_answer_inspection_report_info c ON (b.person_id = c" +
                                        ".patient_id" +
                                        " OR (b" +
                                        ".card_type = c.card_type AND b.card_number = c.card_number)) AND c" +
                                        ".disease_type_id =:diseaseTypeId AND c.item_id =:itemId");
                                sqlBuilder.append(" and c.result >=:bigDecimalItemContent1  and c.result <=:bigDecimalItemContent2 and" +
                                        " " +
                                        "b" +
                                        ".audit_time <= c.answer_time ");
                                sqlBuilder.append(" where a.status = 1 AND a.route_detail_id =:routeDetailId");
                            }
                        }

                        Query query = ss.createSQLQuery(sqlBuilder.toString());
                        query.setParameter("diseaseTypeId", request.getDiseaseTypeId());
                        query.setParameter("itemId", request.getItemId());
                        query.setParameter("routeDetailId", request.getRouteDetailId());
                        query.setParameter("itemContent1", request.getFactorResultOne());
                        if (!qualitative) {
                            query.setParameter("itemContent2", request.getFactorResultTwo());
                            if (longItemContent1 != null && longItemContent2 != null) {
                                query.setParameter("longItemContent1", longItemContent1);
                                query.setParameter("longItemContent2", longItemContent2);
                            }
                            if (doubleItemContent1 != null && doubleItemContent2 != null) {
                                query.setParameter("bigDecimalItemContent1", doubleItemContent1);
                                query.setParameter("bigDecimalItemContent2", doubleItemContent2);
                            }
                        }
                        List list = query.list();
                        List<Long> voList;
                        if (CommonUtils.isNotEmpty(list)) {
                            voList = list;
                        } else {
                            voList = new ArrayList<>();
                        }
                        setResult(voList);
                    }
                };
        HibernateSessionTemplate.instance().execute(action);
        return action.getResult();
    }

    /**
     * @param request
     * @throws
     * @description: 根据诊断和条件是查询
     * @return: java.util.List<java.lang.Long>
     * @author: tongtp
     * @date: 2020/7/23 19:49
     */
    public List<Long> queryByDiagnosisAndYes(final QueryByDiagnosisRequest request) {
        HibernateStatelessResultAction<List<Long>> action =
                new AbstractHibernateStatelessResultAction<List<Long>>() {
                    @Override
                    public void execute(StatelessSession ss) throws Exception {
                        StringBuilder sqlBuilder = new StringBuilder();
                        sqlBuilder.append("SELECT a.id from follow_up_plan_produce_record a INNER JOIN " +
                                "fus_team_chronic_group_record b on a.team_chronic_group_id = b" +
                                ".team_chronic_group_id" +
                                " " +
                                "INNER JOIN fus_answer_diagnosis_info c ON (b.person_id = c.patient_id OR (b" +
                                ".card_type" +
                                " " +
                                "= c.card_type AND b.card_number = c.card_number)) AND c.disease_type_id =:diseaseTypeId AND c.diagnosis_id =:diagnosisId where a.status = 1 AND a" +
                                ".route_detail_id =:routeDetailId and b.audit_time <= c.answer_time ");

                        Query query = ss.createSQLQuery(sqlBuilder.toString());
                        query.setParameter("diseaseTypeId", request.getDiseaseTypeId());
                        query.setParameter("diagnosisId", request.getDiagnosisId());
                        query.setParameter("routeDetailId", request.getRouteDetailId());

                        List list = query.list();
                        List<Long> voList;
                        if (CommonUtils.isNotEmpty(list)) {
                            voList = list;
                        } else {
                            voList = new ArrayList<>();
                        }
                        setResult(voList);
                    }
                };
        HibernateSessionTemplate.instance().execute(action);
        return action.getResult();
    }

    /**
     * @param request
     * @throws
     * @description: 根据诊断和条件否查询
     * @return: java.util.List<java.lang.Long>
     * @author: tongtp
     * @date: 2020/7/23 19:49
     */
    public List<Long> queryByDiagnosisAndNO(final QueryByDiagnosisRequest request) {
        HibernateStatelessResultAction<List<Long>> action =
                new AbstractHibernateStatelessResultAction<List<Long>>() {
                    @Override
                    public void execute(StatelessSession ss) throws Exception {
                        StringBuilder sqlBuilder = new StringBuilder();
                        sqlBuilder.append("SELECT e.id from follow_up_plan_produce_record e INNER JOIN (" +
                                "select c.team_chronic_group_id from fus_team_chronic_group_record c LEFT JOIN " +
                                "(select" +
                                " a.team_chronic_group_id from fus_team_chronic_group_record a INNER JOIN " +
                                "fus_answer_diagnosis_info b on (a.person_id = b.patient_id OR (a.card_type = b" +
                                ".card_type and a.card_number = b.card_number)) and a.chronic_disease_id = b" +
                                ".disease_type_id where a.chronic_disease_id =:diseaseTypeId AND b.diagnosis_id =:diagnosisId and a.audit_time <= b.answer_time) AS d on c.team_chronic_group_id = d" +
                                ".team_chronic_group_id where d" +
                                ".team_chronic_group_id IS NULL AND c.chronic_disease_id =:diseaseTypeId" +
                                ") AS f on e.team_chronic_group_id = f.team_chronic_group_id where e.status = 1 AND " +
                                "e" +
                                ".route_detail_id =:routeDetailId");
                        Query query = ss.createSQLQuery(sqlBuilder.toString());
                        query.setParameter("diseaseTypeId", request.getDiseaseTypeId());
                        query.setParameter("diagnosisId", request.getDiagnosisId());
                        query.setParameter("routeDetailId", request.getRouteDetailId());

                        List list = query.list();
                        List<Long> voList;
                        if (CommonUtils.isNotEmpty(list)) {
                            voList = list;
                        } else {
                            voList = new ArrayList<>();
                        }
                        setResult(voList);
                    }
                };
        HibernateSessionTemplate.instance().execute(action);
        return action.getResult();
    }

    /**
     * @param request
     * @throws
     * @description: 按事件发生事件查询
     * @return: java.util.List<java.lang.Long>
     * @author: tongtp
     * @date: 2020/7/23 20:24
     */
    public List<Long> queryByHappenTime(final QueryByHappenTimeRequest request) {
        HibernateStatelessResultAction<List<Long>> action =
                new AbstractHibernateStatelessResultAction<List<Long>>() {
                    @Override
                    public void execute(StatelessSession ss) throws Exception {
                        StringBuilder sqlBuilder = new StringBuilder();
                        sqlBuilder.append("select * from follow_up_plan_produce_record a INNER JOIN " +
                                "fus_team_chronic_group_record b on a.team_chronic_group_id = b" +
                                ".team_chronic_group_id AND apply_time <= :happenTime AND b.disease_type_id =" +
                                " " +
                                ":diseaseTypeId where a.status = 1 AND a.route_detail_id = :routeDetailId");
                        Query query = ss.createSQLQuery(sqlBuilder.toString());
                        query.setParameter("diseaseTypeId", request.getDiseaseTypeId());
                        query.setParameter("happenTime", request.getHappenTime());
                        query.setParameter("routeDetailId", request.getRouteDetailId());
                        List list = query.list();
                        List<Long> voList;
                        if (CommonUtils.isNotEmpty(list)) {
                            voList = list;
                        } else {
                            voList = new ArrayList<>();
                        }
                        setResult(voList);
                    }
                };
        HibernateSessionTemplate.instance().execute(action);
        return action.getResult();
    }

    public List<FactorData> executeFactorForPathBranch(FollowUpRouteDetailFactorRelation factorRelation, List<String> patientIdList,Byte isLoopExecute,Long routeDetailId, String followType) {
        HibernateStatelessResultAction<List<FactorData>> action =
                new AbstractHibernateStatelessResultAction<List<FactorData>>() {
                    @Override
                    public void execute(StatelessSession ss) throws Exception {
                        StringBuilder sqlBuilder = new StringBuilder();
                        sqlBuilder.append("select patientId,routeDetailId,dataSource from (");
                        sqlBuilder.append("SELECT  DISTINCT g.patient_id as patientId,route_detail_id routeDetailId, '1' as dataSource , ");
                        sqlBuilder.append(" ( SELECT COUNT(record_id) FROM follow_up_records WHERE patient_id=g.person_id AND route_detail_id=p.route_detail_id )  AS times ");
                        sqlBuilder.append(" FROM  follow_up_plan_produce_record p   LEFT JOIN fus_team_chronic_group_record g ");
                        sqlBuilder.append(" ON p.team_chronic_group_id = g.team_chronic_group_id WHERE p.route_detail_id=:routeDetailId ");
                        if (CommonUtils.isNotEmpty(factorRelation.getRouteBranchStatus()) ) {
                            sqlBuilder.append(" and  p.status =:status ");
                        }
                        if (CommonUtils.isNotEmpty(patientIdList) ) {
                            sqlBuilder.append(" AND g.patient_id IN (:patientIdList)");
                        }
                        if (CommonUtils.isNotEmpty(factorRelation.getRouteBranchExecuteNum()) ) {
                            sqlBuilder.append(" HAVING times =:executionTimes");
                        }
                        sqlBuilder.append(") AS  m ");
                        //循环执行机制 0 不执行 1 执行
                        if (FollowTypeEnum.FUS_SPECIALIST.getType().equals(followType) && null != isLoopExecute && isLoopExecute == 1) {
                            sqlBuilder.append(" LEFT JOIN fus_factor_data_record f  ON f.patient_id = m.patientId   AND f.route_detail_id = :routeDetailId AND f.route_detail_id = m.routeDetailId WHERE f.id IS NULL  ");
                        }
                        Query query = ss.createSQLQuery(sqlBuilder.toString());
                        query.setParameter("routeDetailId", factorRelation.getRouteDetailId());
                        if (CommonUtils.isNotEmpty(factorRelation.getRouteBranchStatus()) ) {
                            query.setParameter("status", factorRelation.getRouteBranchStatus());
                        }
                        if (CommonUtils.isNotEmpty(factorRelation.getRouteBranchExecuteNum()) ) {
                            query.setParameter("executionTimes", factorRelation.getRouteBranchExecuteNum());
                        }
                        if (CommonUtils.isNotEmpty(patientIdList) ) {
                            query.setParameterList("patientIdList",patientIdList);
                        }
                        if (FollowTypeEnum.FUS_SPECIALIST.getType().equals(followType) && null != isLoopExecute && isLoopExecute == 1) {
                            query.setParameter("routeDetailId", routeDetailId);
                        }
                        List list = query.list();
                        List<FactorData> voList;
                        if (CommonUtils.isNotEmpty(list)) {
                            voList = list;
                        } else {
                            voList = new ArrayList<>();
                        }
                        setResult(voList);
                    }
                };
        HibernateSessionTemplate.instance().execute(action);
        return action.getResult();
    }
}
